<template>
  <el-container class="app-wrapper" :class="classObj" style="min-height: 100vh;">
    <el-aside :width="sidebarWidth" class="sidebar-elevated" style="min-height: 100vh;">
      <sidebar :class="{ 'has-logo': showLogo }" />
    </el-aside>
    <el-container class="main-container" style="min-height: 100vh;">
      <el-header height="auto" class="fixed-header">
        <navbar />
        <tags-view v-if="needTagsView" />
      </el-header>
      <el-main>
        <app-main />
      </el-main>
      <right-panel v-if="showSettings">
        <settings />
      </right-panel>
    </el-container>
  </el-container>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { useAppStore } from '@/stores/app'
import { useUserStore } from '@/stores/user'
import Navbar from './components/Navbar/index.vue'
import Sidebar from './components/Sidebar/index.vue'
import AppMain from './components/AppMain/index.vue'
import TagsView from './components/TagsView/index.vue'
import RightPanel from '@/components/RightPanel/index.vue'
import Settings from './components/Settings/index.vue'

const appStore = useAppStore()
const userStore = useUserStore()

// 计算属性
const classObj = computed(() => ({
  hideSidebar: appStore.sidebarCollapsed,
  openSidebar: !appStore.sidebarCollapsed,
  withoutAnimation: appStore.sidebarWithoutAnimation,
  mobile: appStore.device === 'mobile'
}))

const device = computed(() => appStore.device)
const sidebarCollapsed = computed(() => appStore.sidebarCollapsed)
const needTagsView = computed(() => appStore.showTabs)
// 由配置控制Logo显示（默认显示）
const showLogo = computed(() => import.meta.env.VITE_SHOW_LOGO !== 'false')
// 右侧设置面板：仅管理员可见，且需显式开启
const showSettings = computed(() => import.meta.env.VITE_SHOW_SETTINGS === 'true' && userStore.isSuperAdmin)

// 侧栏宽度（随折叠变化）
const sidebarWidth = computed(() => (appStore.sidebarCollapsed ? '64px' : '240px'))
</script>

<style lang="scss" scoped></style>
